<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>产品配置</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script type="text/javascript">
	var startP = 1;
	$(document).ready(function() {
		//初始读取数据
		loadProductData();
	});
	function bindradio(){
		$("input[type='radio']").click(function(){
			$("input[name='radioProduct']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");

       	});
	}

	function queryProduct(displayPage){
		var tradProdCode= $("#tradProdCode").val();
		var tradProdDesc= $("#tradProdDesc").val();
		var status= $("#status").val();
		var startDate= $("#startDate").val();
		var endDate= $("#endDate").val();
		loadProductData({current:displayPage,size:10,tradProdCode:tradProdCode,tradProdDesc:tradProdDesc,status:status,startDate:startDate,endDate:endDate});
	}
	function loadProductData(param){
		   
		   var jsonDate;
		   
			if(null != param && null != param.current){
				var str = "";
				var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
				var startDate = param.startDate;
				var endDate = param.endDate;
				if(null != startDate && "" != startDate){
					if(startDate.match(strReg)==null){
						$.message("error", "您输入的定义起期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				if(null != endDate && "" != endDate){
					if(endDate.match(strReg)==null){
						$.message("error", "您输入的定义止期格式不正确，格式为:YYYY-MM-DD");
						return;
					}
				}
				jsonDate =param;
				
			}else{
				jsonDate={current:1,size:10};
			}
			$.openLoading();
			$.ajax({
					url : "product/queryList",
					type : 'POST',
					async : true,
					dataType:'json',
					data:jsonDate,
					success : function(page) {
						    $.closeLoading();
							if($.validate(page))return;
							startP = page.current;
							var firstbutton ="<input class='input_fxk' name='radioProduct' type='radio' value='#'>";

							var lastbutton = "<a href='javascript:void(0)' onClick='editTradProdInst(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delTradProdInst(this);return false'>删除</a>";
							var tableContent = creatTable1("tradProdCode,tradProdDesc,startDate,instant?[{Y:'是'};{N:'否'}],status?[{0:'无效'};{1:'有效'}]",page,firstbutton,lastbutton);
							
							var tableObj = $("#gatewayproductTable");
							tableObj.find("tbody").remove();
							tableObj.append(tableContent);
							var strPage = creatChannelPage(startP,6,page.maxPage,"7");
							var pageDIV = $("#txproductpageDIV");
							pageDIV[0].innerHTML="";
							
							pageDIV.append(strPage);
							
							bindradio();
					}
				});
		}
	function delTradProdInst(obj){
		
		
		$.dialog({
			type: "warn",//success,error
			content: "您确定要删除该产品吗？",
			/*重写
			onCancel:function(){
				alert("onCancel:function");
			},
			onClose:function(){
				alert("onClose:function");
			},*/
			onOk: function() {
				var editTr = $(obj).parent('td').parent('tr')[0];
				var tradProdCode = editTr.childNodes[1].innerHTML;
				deleteTradProdInst(tradProdCode);
			}
		});
	}
	function deleteTradProdInst(tradProdCode){
		$.openLoading();
		$.ajax({
			url : "product/delete",
			type : 'POST',
			async : true,
			dataType:'json',
			data:{
				tradProdCode:tradProdCode
			},
			success : function(obj) {
				$.closeLoading();
				if($.validate(obj))return;
				queryProduct(1);
			}
		});
	}
	function editTradProdInst(obj){
		var editTr = $(obj).parent('td').parent('tr')[0];
		var tradProdCode = editTr.childNodes[1].innerHTML;
		window.location.href='<%=basePath%>product/edit?tradProdCode='+tradProdCode;
	}
	
	function vreset(){
		$("#tradProdCode").val("");
		$("#tradProdDesc").val("");
		$("#startDate").val("");
		$("#endDate").val("");
		$("#status").val("");
	}
	function add(){
		window.location.href='<%=basePath%>product/add';
	}
	function insuranceAdd(){
		var radioProduct = $("input[name='radioProduct']:checked");
//		var prodDesc = radioProduct.parent().parent().children(" td:eq(2)").html();
		if(radioProduct.val()!=undefined){
			var tradProdCode = radioProduct.val();
			window.location.href='<%=basePath%>product/prodPlan?tradProdCode='+tradProdCode;
		}else{
			$.message("error", "请选择一个产品");
		}
		
		
	}
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">产品管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="20%" height="30">产品代码：
								<input name="txt3" id="tradProdCode" type="text" class="input_text" value="">
							</td>
							<td width="20%" height="30">产品描述：
								<input name="txt3" id="tradProdDesc" type="text" class="input_text" value="">
							</td>
							<td width="20%" height="30">状态：
							 	<select class="search_select_1" id="status">
									<option value="">--请选择--</option>
									<option value="1">有效</option>
									<option value="0">无效</option>
								</select>
							</td>
							<td width="20%" height="30">定义起期：
								<input id="startDate" onkeydown="false" onclick="showCalendar('startDate','y-mm-dd');" class="input_time" type="text" />
							</td>
							<td width="20%" height="30">定义止期：
								 <input id="endDate" onkeydown="false" onclick="showCalendar('endDate','y-mm-dd');" class="input_time" type="text" />
							</td>
						</tr>
						<tr height="30px">
							<td style="text-align: center;" colspan="5" width="100%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryProduct(1)" />&nbsp;
							    <input type="button" class="input_button_1" id="searchBtn" value="重置" onClick="vreset()" />
							</td>
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="100%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="新增" onClick="add()" />&nbsp;
								<input type="button" class="input_button_2" id="searchBtn" value="险种配置" onClick="insuranceAdd()"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="gatewayproductTable" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:3%;">选择</th>
								<th style="width:6%;">交易系统产品代码</th>
								<th>交易系统产品描述</th>
								<th style="width:5%;">定义时间</th>
								<th style="width:3%;">即时投保</th>
								<th style="width:3%;">状态</th>
								<th style="width:3%;">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txproductpageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		
		<div id="detail" style="display: none;">
			<div id="input" style="margin: 5px;h word-wrap: break-word"></div>
		</div>
		<div id="detail2" style="display: none;">
			<h4 style="background-color: #A4BDE3;"></h4>
			<table>
				<thead></thead>
				<tr>
					<td width="200px"></td>
					<td align="right"><img src="./images/closedown.gif"
						onclick="closeDiv()" /></td>
				</tr>
			</table>
			<input type="hidden" id="appId" value="">

			<div id="output" style="margin: 5px; word-wrap: break-word"></div>
		</div>
	</div>
</body>
</html>